<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.min.js"></script>
  </head>
  <body>
    <button type="button" class="btn btn-default" id="btn">测试按钮</button>
    <script>
      $(function () {
        // let url = 'http://dlgj.dlitg.com/report/reportAction/testSign.exc'
        let url = 'http://192.168.10.180:8080/reportAction/testSign.exc'
        let sendMaxNum = 100
        let $btn = $('#btn')
        let data = { sid: 'S10201_9996_16336716822050011', sys_requestType: 'ajax' }
        let ajaxNameArr = []

        $btn.click(() => {
          this.ajaxNameArr = []
          for (let i = 0; i < sendMaxNum; i++) {
            window['testFn' + i] = new Promise((resolve, reject) => {
              $.ajax({
                type: 'POST',
                url,
                data,
                dataType: 'json',
                success: function (res) {
                  if (res.resultType === 0) {
                    resolve(res)
                  } else {
                    reject(res.message)
                  }
                },
                error: function (err) {
                  reject(err)
                }
              })
            })
            ajaxNameArr.push(window['testFn' + i])
          }
          Promise.all(ajaxNameArr)
            .then(res => {
              console.log('[ res ] >', res)
            })
            .catch(error => {
              console.error(error)
            })
        })

        function sendAjax(url, data) {
          return new Promise((resolve, reject) => {
            $.ajax({
              type: 'POST',
              url,
              data,
              dataType: 'json',
              success: function (data) {
                resolve(data)
              },
              error: function (err) {
                reject(err)
              }
            })
          })
        }
      })
    </script>
  </body>
</html>
